package com.example.score;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import com.example.score.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    MyViewModel myViewModel;
    ActivityMainBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main);    //绑定布局
//        myViewModel = ViewModelProviders.of(this).get(MyViewModel.class);  已过时
        myViewModel = new ViewModelProvider(this).get(MyViewModel.class);

        binding.setMyData(myViewModel);     //绑定layout中的@{}内容
        binding.setLifecycleOwner(this);          //观察数据是否有改变


    }
}